package com.exam.action;

import java.util.ArrayList;
import java.util.List;

import com.exam.bean.PaperContentType;
import com.exam.bean.PaperSourceType;
import com.exam.service.PaperContentTypeService;
import com.exam.service.PaperSourceTypeService;
import com.exam.service.impl.PaperContentTypeServiceImpl;
import com.exam.service.impl.PaperSourceTypeServiceImpl;
import com.exam.util.Page;
import com.exam.util.PageResult;
import com.opensymphony.xwork2.ActionSupport;

public class PaperTypeAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private List<PaperContentType> pctList = new ArrayList<PaperContentType>();
	private List<PaperSourceType> pstList = new ArrayList<PaperSourceType>();
	private Page pagePct = new Page();
	private Page pagePst = new Page();

	public String list() {
		PaperContentTypeService pcts = new PaperContentTypeServiceImpl();
		PaperSourceTypeService psts = new PaperSourceTypeServiceImpl();
		try {
			listForContentTypePageService(pcts, "");
			listForSourceTypePageService(psts, "");
		} catch (Exception e) {
			return "exception";
		}
		return "list";
	}

	// 为分页处理服务的方法
	@SuppressWarnings("unchecked")
	public void listForContentTypePageService(PaperContentTypeService pcts,
			String strWhere) throws Exception {
		PageResult pageResult = null;
		pagePct.setEveryPage(15);
		if (strWhere != null && !"".equals(strWhere)) {
			pageResult = pcts.findListByPage(strWhere, pagePct);// 按条件查询
		} else {
			pageResult = pcts.findListByPage(pagePct);// 简单分页
		}
		pagePct = pageResult.getPage();// 获得分页信息
		pctList = pageResult.getList();// 获得记录
	}

	@SuppressWarnings("unchecked")
	public void listForSourceTypePageService(PaperSourceTypeService psts,
			String strWhere) throws Exception {
		PageResult pageResult = null;
		pagePst.setEveryPage(15);
		if (strWhere != null && !"".equals(strWhere)) {
			pageResult = psts.findListByPage(strWhere, pagePst);// 按条件查询
		} else {
			pageResult = psts.findListByPage(pagePst);// 简单分页
		}
		pagePst = pageResult.getPage();// 获得分页信息
		pstList = pageResult.getList();// 获得记录

	}

	/**
	 * @param pctList
	 *            the pctList to set
	 */
	public void setPctList(List<PaperContentType> pctList) {
		this.pctList = pctList;
	}

	/**
	 * @return the pctList
	 */
	public List<PaperContentType> getPctList() {
		return pctList;
	}

	/**
	 * @param pstList
	 *            the pstList to set
	 */
	public void setPstList(List<PaperSourceType> pstList) {
		this.pstList = pstList;
	}

	/**
	 * @return the pstList
	 */
	public List<PaperSourceType> getPstList() {
		return pstList;
	}

	public Page getPage() {
		return pagePct;
	}

	public void setPage(Page page) {
		this.pagePct = page;
	}

	/**
	 * @param pagePst
	 *            the pagePst to set
	 */
	public void setPagePst(Page pagePst) {
		this.pagePst = pagePst;
	}

	/**
	 * @return the pagePst
	 */
	public Page getPagePst() {
		return pagePst;
	}
}
